#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jul  1 00:30:17 2024

@author: liqingsimac
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
from matplotlib.colors import ListedColormap

# 参数化玫瑰花瓣
def parametric_rose(n_petals, n_points=100):
    theta = np.linspace(0, 2 * np.pi, n_points, endpoint=False)
    r = np.cos(n_petals * theta / 2) ** 2
    x = r * np.cos(theta)
    y = r * np.sin(theta)
    return x, y

# 设置花瓣数量和点数
n_petals = 8  # 玫瑰通常有多个花瓣，这里简化为8瓣
n_points = 200

# 生成花瓣
petals_x, petals_y = parametric_rose(n_petals, n_points)
petals = np.array([petals_x, petals_y]).T.reshape(-1, 1, 2)
petals = np.concatenate([petals[:-1], petals[::-1]], axis=1)

# 创建颜色映射，从中心到边缘变化
colors = plt.cm.viridis(np.linspace(0, 1, petals.shape[0]))

# 绘制
fig, ax = plt.subplots(figsize=(6, 6))
collection = PolyCollection(petals, facecolors=colors, edgecolors=colors, linewidth=0.5)
ax.add_collection(collection)

# 设置边界和隐藏坐标轴
ax.set_xlim([-1.5, 1.5])
ax.set_ylim([-1.5, 1.5])
ax.axis('off')

#plt.show()
